import { getListApi as getAllPaymentApi } from "@/api/configCenter/paymentManagement";
import { getTreeChannelApi } from "@/api/configCenter/warehouseEntryChannel";
import { getListApi as getDriverApi } from "@/api/managementCenter/driverManagement";
import { getCustomerSelectList } from "@/api/managementCenter/customerManagement";
import { TreeSelect } from "ant-design-vue";
const SHOW_CHILD = TreeSelect.SHOW_CHILD;

import { reactive } from "vue";

export const searchItemList: Array<SuperSearch.SearchItem> = [
  {
    type: "input",
    label: "运单号",
    keyName: "waybillNums",
    placeholder: "支持批量(空格/逗号隔开)"
  },
  reactive<SuperSearch.SearchItem>({
    type: "select",
    label: "客户简称",
    keyName: "customerIdList",
    optionsRequest: getCustomerSelectList,
    optReqParams: { isFilterChild: 0 },
    optReqCb: (res: Base.GeneraDataType, row: SuperSearch.SearchItem) => {
      const { code, data } = res;
      if (code === 200) {
        row.options = data || [];
      }
    },
    attrs: {
      mode: "multiple"
    },
    optConfig: {
      label: "shortName",
      value: "id"
    },
    options: []
  }),
  reactive<SuperSearch.SearchItem>({
    type: "cascader",
    label: "渠道",
    keyName: "channelIdList",
    optionsRequest: getTreeChannelApi,
    optReqParams: {},
    optReqCb: (res: Base.GeneraDataType, row: SuperSearch.SearchItem) => {
      const { code, data } = res;
      if (code === 200) {
        row.options = data || [];
      }
    },
    optConfig: {
      label: "label",
      value: "value",
      children: "children"
    },
    attrs: {
      multiple: true,
      showCheckedStrategy: SHOW_CHILD
    },
    options: []
  }),

  reactive<SuperSearch.SearchItem>({
    type: "select",
    label: "账期",
    keyName: "accountPeriodIdList",
    optionsRequest: getAllPaymentApi,
    optReqParams: { status: 1, pageNum: 1, pageSize: 9999999, total: 0 },
    optReqCb: (res: Base.GeneraDataType, row: SuperSearch.SearchItem) => {
      const { code, data } = res;
      if (code === 200) {
        row.options = data.records || [];
      }
    },
    optConfig: {
      label: "accountName",
      value: "id"
    },
    attrs: {
      mode: "multiple"
    },
    options: []
  }),

  reactive<SuperSearch.SearchItem>({
    type: "select",
    label: "收货司机",
    keyName: "driverUserIdList",
    optionsRequest: getDriverApi,
    optReqParams: { pageNum: 1, pageSize: 9999999 },
    optReqCb: (res: Base.GeneraDataType, row: SuperSearch.SearchItem) => {
      const { code, data } = res;
      if (code === 200) {
        row.options = data.records || [];
      }
    },
    optConfig: {
      label: "username",
      value: "userId"
    },
    attrs: {
      mode: "multiple"
    },
    options: []
  })
];

// 列表
export const tableColumn: Array<SuperTable.TableCoulmnItem | SuperTable.NestTableColumnItem> = [
  {
    type: "checkbox",
    field: "checkbox",
    minWidth: "50",
    fixed: "left"
  },
  {
    field: "waybillNum",
    title: "运单号",
    minWidth: "140"
  },
  {
    field: "shortName",
    title: "客户简称",
    minWidth: "100"
  },
  {
    field: "accountName",
    title: "账期",
    minWidth: "100"
  },
  {
    field: "customerName",
    title: "客户名称",
    minWidth: "220"
  },

  {
    field: "depositTime",
    title: "拣货时间",
    minWidth: "140",
    formatter: "formatDate"
  },
  {
    field: "channelName",
    title: "渠道",
    minWidth: "160"
  },
  {
    field: "countryRegionName",
    title: "目的地",
    minWidth: "90"
  },

  {
    field: "itemNumber",
    title: "件数",
    minWidth: "80"
  },

  {
    field: "agentSettlementWeight",
    title: "客户结算重",
    minWidth: "100"
  },
  {
    field: "receivableTotalPrice",
    title: "合计应收",
    minWidth: "100"
  },

  {
    field: "bizPayableTotalPrice",
    title: "合计应付",
    minWidth: "100"
  },
  {
    field: "bizMargin",
    title: "毛利润",
    minWidth: "100"
  },
  {
    field: "bizMarginUnit",
    title: "毛利率",
    minWidth: "100"
  },
  {
    field: "companyName",
    title: "经营单位",
    minWidth: "80"
  },
  {
    field: "bizName",
    title: "业务",
    minWidth: "80"
  },
  {
    field: "finName",
    title: "财务",
    minWidth: "80"
  },
  {
    field: "followName",
    title: "跟单",
    minWidth: "80"
  },
  {
    field: "checkingStatusName",
    title: "对账状态",
    minWidth: "80"
  },
  {
    field: "adjustPrice",
    title: "优惠金额",
    minWidth: "80"
  },
  {
    field: "driverUserName",
    title: "收货司机",
    minWidth: "80"
  }
];
